<?php
/*
 * 主要管理首页，其他文章页
 */
class IndexAction extends CommonAction{
    public function index(){
       /*$summary = '
         <div id="summary">
            <div class="summary-warp">
                <div class="summary-content">
                    <h1>上海好家服务公寓</h1>
                    <p>上海好家服务公寓隶属于上海成帝房产咨询有限公司，整合城市住宅资源与酒店服务理念，为商务出差，学习培训，探亲访友，休闲旅游提供2天到1年的酒店式公寓租赁服务
                    （1）比同品质宾馆酒店便宜至少40%-50%（2）可洗衣做饭，更适合人性化生活住宿。——珍惜所托，用心服务! </p>
                </div>
            </div>
        </div>
        ';
        $this->assign('summary',$summary);*/
        //SEO
        $title = "上海酒店式公寓酒店-上海短期租房-上海短租公寓-比高档酒店宾馆便宜";
        $home_meta = M('Meta')->where('type="Index" and tid="index"')->find();
        $title = empty($home_meta['title']) ? $title : $home_meta['title'];
        $this->assign('title',$title);
        $desc = "上海好家服务公寓为到上海的朋友提供2天到1年的酒店式公寓租赁服务,比同品质宾馆酒店便宜至少40%-50%,可洗衣做饭，更适合人性化生活住宿";
        $desc = empty($home_meta['description']) ? $desc : $home_meta['description'];
        $this->assign('desc',$desc);
        $this->assign('keywords',$home_meta['keywords']);

        import("@.ORG.Util.Page");
        //直营房源
        $map = array(
            'Hotel.status'=>1,
            'Hotel.type'=>1,//直营
            'attachfunc'=> 2,//logo必须上传，否则不能显示
        );
        $hotel = D('HotelView')->where($map)->order('sort,create_time asc')->findAll();
        $countHotel = count($hotel);
        $Page = new Page($countHotel,10);//每页显示10个
        $show = $Page ->show();
        $list = D('HotelView')->where($map)->limit($Page->firstRow.",".$Page->listRows)->order('sort,create_time asc')->findAll();
        $this->assign('hotel',$list);
        $this->assign("page",$show);

        //联盟房源TODO
        $map2 = array(
            'Hotel.status'=>1,
            'Hotel.type'=>0,//联盟
            'attachfunc'=> 2,//logo必须上传，否则不能显示
        );
        $union_hotel = D('HotelView')->where($map2)->order('sort,create_time asc')->findAll();
        $countHotel2 = count($union_hotel);
        $Page2 = new Page($countHotel2,10);//每页显示10个
        $show2 = $Page2 ->show();
        $list2 = D('HotelView')->where($map2)->limit($Page2->firstRow.",".$Page2->listRows)->order('sort,create_time asc')->findAll();
        $this->assign('union_hotel',$list2);
        $this->assign("page2",$show2);
        $Form = M('Form');
        $this->assign('notice',$Form->where('cid =66 and status=1')->order('create_time desc')->find());//公告id暂取48,只取最新一条公告
        $this->assign('articleList',$Form->where('(cid=64) and status=1')->order('create_time desc')->limit(30)->findAll());//百事通id暂取49，50，51
        $this->assign('ads',M('Ad')->order('sort')->limit(5)->findAll() );//暂时只显示5个图片
        $this->assign('home',1);
        $this->display();
    }

    //联盟公寓
    public function union(){
        //SEO
        $title = "上海酒店式公寓联盟公寓-比高档酒店宾馆便宜";
        $home_meta = M('Meta')->where('type="Index" and tid="union"')->find();
        $title = empty($home_meta['title']) ? $title : $home_meta['title'];
        $this->assign('title',$title);
        $desc = "上海好家服务公寓为到上海的朋友提供2天到1年的酒店式公寓租赁服务,比同品质宾馆酒店便宜至少40%-50%,可洗衣做饭，更适合人性化生活住宿";
        $desc = empty($home_meta['description']) ? $desc : $home_meta['description'];
        $this->assign('desc',$desc);
        $this->assign('keywords',$home_meta['keywords']);

        import("@.ORG.Util.Page");
        //联盟房源TODO
        $map2 = array(
            'Hotel.status'=>1,
            'Hotel.type'=>0,//联盟
            'attachfunc'=> 2,//logo必须上传，否则不能显示
        );
        $union_hotel = D('HotelView')->where($map2)->order('sort,create_time asc')->findAll();
        $countHotel2 = count($union_hotel);
        $Page2 = new Page($countHotel2,10);//每页显示10个
        $show2 = $Page2 ->show();
        $list2 = D('HotelView')->where($map2)->limit($Page2->firstRow.",".$Page2->listRows)->order('sort,create_time asc')->findAll();
        $this->assign('union_hotel',$list2);
        $this->assign("page2",$show2);
        $this->assign('articleList',M('Form')->where('(cid=64) and status=1')->order('create_time desc')->limit(30)->findAll());//百事通id暂取49，50，51
       
        $this->display();

    }

    /**
     * 展示文章
     */
    public function page(){
        $id = intval( $_GET['id'] );
        $page = M('Form')->where('id ='.$id.' and status=1')->find();
        if(is_array($page)){
            $this->assign('page',$page);

            //SEO
            $meta_title = empty($page['meta_title']) ? $page['title'] : $page['meta_title'];
            $this->assign('title',$meta_title);
            $meta_description = empty($page['meta_description']) ? cutstr( getDesc($page['content']),400 ) : $page['meta_description'];
            $this->assign('desc',$meta_description );
            $this->assign('keywords',$page['meta_keywords']);

            $this->display();
        }
        else{
            $this->assign('jumpUrl', __APP__.'/');
            $this->error("对不起，您查看的文章暂时不可用，请返回！",false,10);
        }
        
    }

    /**
     * 帮助类的文章
     */
    public function help(){
        //帮助中心ID= 73
        import("@.ORG.Util.Page");
        $page = M('Form')->where('(cid=73) and status=1')->order('create_time desc')->findAll();
        $pp = new Page(count($page),20);
        $list = M('Form')->where('(cid=73) and status=1')->order('create_time desc')->limit($pp->firstRow.','.$pp->listRows)->findAll();
        if(is_array($page)){
            $this->assign('articles',$list);
            $this->assign('help','帮助中心');
            //SEO
            $meta_title = empty($list['meta_title']) ? $list['title'] : $list['meta_title'];
            $this->assign('title',$meta_title);
            $meta_description = empty($list['meta_description']) ? cutstr( getDesc($list['content']),400 ) : $list['meta_description'];
            $this->assign('desc',$meta_description );
            $this->assign('keywords',$list['meta_keywords']);

            $this->assign('page', $pp->show());
            $this->display('listing');
        }
        else{
            $this->assign('jumpUrl', __APP__.'/');
            $this->error("对不起，您查看的文章暂时不可用，请返回！",false,10);
        }

    }

    /**
     * 展示新闻，要对新闻进行范围控制
     */
    public function news(){
        $id = intval( $_GET['id'] );
        $page = M('Form')->where('id ='.$id.' and status=1')->order('create_time desc')->find();
        $this->assign('hotelList',M('Hotel')->where('status = 1 and id !='.$id)->order('sort')->getField('id,name'));
            
        if(is_array($page)){
            $this->assign('page',$page);
            //SEO
            $meta_title = empty($page['meta_title']) ? $page['title'] : $page['meta_title'];
            $this->assign('title',$meta_title);
            $meta_description = empty($page['meta_description']) ? cutstr( getDesc($page['content']),400 ) : $page['meta_description'];
            $this->assign('desc',$meta_description );
            $this->assign('keywords',$page['meta_keywords']);
            $this->display();
        }
        else{
            $this->assign('jumpUrl', __APP__.'/');
            $this->error("对不起，您查看的新闻暂时不可用，请返回！",false,10);
        }
    }

      /**
     * 文章列表
     */
    public function listing(){
        $id = intval( $_GET['id'] );
        import("@.ORG.Util.Page");
        $page = M('Form')->where('cid ='.$id.' and status=1')->findAll();
        $pp = new Page(count($page),20);
        $list = M('Form')->where('cid ='.$id.' and status=1')->limit($pp->firstRow.','.$pp->listRows)->order('create_time desc')->findAll();
        if(is_array($page)){

            $this->assign('articles',$list);//文章列表
            $this->assign('title',$page['title']);
            $this->assign('desc',cutstr( getDesc($page['content']),400 ) );
            $this->assign('hotelList',M('Hotel')->where('status = 1 and id !='.$id)->order('sort')->getField('id,name'));
            $this->assign('page', $pp->show());
            $this->display();
        }
        else{
            $this->assign('jumpUrl', __APP__.'/');
            $this->error("对不起，您查看的新闻暂时不可用，请返回！",false,10);
        }
    }
    //友情链接
    public function link(){
        $count = M("Link")->count('id');
        $list = M('Link')->where('logo ="" or logo is Null')->findAll();
        $this->assign("list", $list);//文字链接
        //图片链接
        $this->assign("img_list", M('Link')->where ('logo !="" or logo is not Null')->findAll());//文字链接
        $this->assign('hotelList',M('Hotel')->where('status = 1 ')->order('sort')->limit(20)->getField('id,name'));
        $this->assign('title',"友情链接");
        $this->display();
    }

}
?>
